package com.burpee.dao;

import java.util.List;

import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.burpee.ui.ExerciseOrder;
import com.burpee.ui.FoodSchedule;

@Repository(value="foodscheduleDao")
public class FoodScheduleDaoImpl implements FoodScheduleDao {
	
	SqlSessionTemplate sqlSessionTemplate;

	@Autowired
	public void setSessionTemplate(SqlSessionFactory sqlSessionFactory) {
		this.sqlSessionTemplate = new SqlSessionTemplate(sqlSessionFactory);
	}

	public List<FoodSchedule> list() {
		
		List<FoodSchedule> list = null;

		try {
			list = sqlSessionTemplate.selectList("foodschedulelist");
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		return list;
	}

	public FoodSchedule view(FoodSchedule foodSchedule) {
		FoodSchedule foodScheduleview = new FoodSchedule();

		try {
			foodScheduleview = sqlSessionTemplate.selectOne("foodscheduleview", foodSchedule);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		return foodScheduleview;
	}

	public int add(FoodSchedule foodSchedule) {
		int result = 0;

		try {
			result = (int)sqlSessionTemplate.insert("foodscheduleadd",foodSchedule);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		return result;
	}

	public int modify(FoodSchedule foodSchedule) {
		int result = 0;

		try {
			result = (int)sqlSessionTemplate.update("foodschedulemodify",foodSchedule);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		return result;
	}

	public int remove(FoodSchedule foodSchedule) {
		int result = 0;

		try {
			result = (int)sqlSessionTemplate.update("foodscheduleremove",foodSchedule);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		return result;
	}

}
